package pwd.allen.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.io.Serializable;
import java.util.Date;

/**
 * @author pwd
 * @create 2018-11-11 12:18
 **/
@Data
@NoArgsConstructor
@RequiredArgsConstructor
public class Person implements Serializable {
    @NonNull
    private Integer id;

    @NonNull
    @Value("${person.name}")
    private String userName;

    @NonNull
    @Value("#{20+6} ")
    private Integer age;

    @Qualifier("fruit")
    @Autowired
    private Fruit fruit;

    /**
     * JsonFormat是json或者xml的情况下才有效的，例如application/json
     * @see MappingJackson2HttpMessageConverter
     * 如果是get请求或者application/x-www-form-urlencoded这种，可以用DateTimeFormat
     * 也可以实现Converter<String, Date>并注册到spring mvc中，全局有效
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createAt;

    @JsonIgnore
    private Fruit fruitTwo = new Fruit("忽略我", 0f, null);
}
